
#include "vector3.h"

#define _USE_MATH_DEFINES
#include <math.h>

float rad(const float a)
{
    return a*M_PI/180.f;
}

void Vector3f_Init(Vector3f* v, const float x, const float y, const float z)
{
    v->x = x;
    v->y = y;
    v->z = z;
}

void Vector3f_InitFromAngle(Vector3f* v, const float a, const float b)
{
    v->x = cos(a)*cos(b);
    v->z = cos(a)*sin(b);
    v->y = sin(a);
}

void Vector3f_Add(Vector3f* R, const Vector3f* A, const Vector3f* B)
{
    R->x = A->x+B->x;
    R->y = A->y+B->y;
    R->z = A->z+B->z;
}

void Vector3f_Sub(Vector3f* R, const Vector3f* A, const Vector3f* B)
{
    R->x = A->x-B->x;
    R->y = A->y-B->y;
    R->z = A->z-B->z;
}

void Vector3f_Mul(Vector3f* R, const float a, const Vector3f* B)
{
    R->x = a*B->x;
    R->y = a*B->y;
    R->z = a*B->z;
}

float Vector3f_Dot(const Vector3f* A, const Vector3f* B)
{
    return A->x*B->x + A->y*B->y + A->z*B->z;
}

void Vector3f_Cross(Vector3f* R, const Vector3f* A, const Vector3f* B)
{
    R->x = A->y*B->z-A->z*B->y;
    R->y = A->z*B->x-A->x*B->z;
    R->z = A->x*B->y-A->y*B->x;
}

void Vector3f_Normalize(Vector3f* v)
{
    float n=sqrt( v->x*v->x + v->y*v->y + v->z*v->z);
    v->x /= n;
    v->y /= n;
    v->z /= n;
}

float Vector3f_Length(const Vector3f* v)
{
    return sqrt( v->x*v->x + v->y*v->y + v->z*v->z);
}
